package cn.sfrog.project.biz.admin.controller;

import cn.sfrog.common.annotation.Log;
import cn.sfrog.common.core.controller.BaseController;
import cn.sfrog.common.core.page.TableDataInfo;
import cn.sfrog.common.enums.BusinessType;
import cn.sfrog.common.utils.poi.ExcelUtil;
import cn.sfrog.project.biz.admin.domain.BizAgency;
import cn.sfrog.project.biz.admin.domain.vo.BizAgencyVO;
import cn.sfrog.project.biz.admin.service.IBizAgencyService;
import cn.sfrog.common.core.domain.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Api(tags = "管理后台-代理")
@RestController
@RequestMapping("/system/agency")
public class BizAgencyController extends BaseController
{
    @Autowired
    private IBizAgencyService bizAgencyService;

    /**
     * 查询【请填写功能名称】列表
     */
    @ApiOperation("查询列表")
    @PreAuthorize("@ss.hasPermi('system:agency:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizAgency bizAgency)
    {
        startPage();
        List<BizAgencyVO> list = bizAgencyService.selectBizAgencyList(bizAgency);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @ApiOperation("导出")
    @PreAuthorize("@ss.hasPermi('system:agency:export')")
    @Log(title = "导出", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizAgency bizAgency)
    {
        List<BizAgencyVO> list = bizAgencyService.selectBizAgencyList(bizAgency);
        ExcelUtil<BizAgencyVO> util = new ExcelUtil<BizAgencyVO>(BizAgencyVO.class);
        util.exportExcel(response, list, "导出代理数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @ApiOperation("详情")
    @PreAuthorize("@ss.hasPermi('system:agency:query')")
    @GetMapping(value = "/{agencyId}")
    public AjaxResult getInfo(@PathVariable("agencyId") Long agencyId)
    {
        return AjaxResult.success(bizAgencyService.selectBizAgencyByAgencyId(agencyId));
    }

    /**
     * 新增【请填写功能名称】
     */
    @ApiOperation("新增")
    @PreAuthorize("@ss.hasPermi('system:agency:add')")
    @Log(title = "添加代理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizAgency bizAgency)
    {
        return toAjax(bizAgencyService.insertBizAgency(bizAgency));
    }

    /**
     * 修改【请填写功能名称】
     */
    @ApiOperation("修改")
    @PreAuthorize("@ss.hasPermi('system:agency:edit')")
    @Log(title = "修改代理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizAgency bizAgency)
    {
        return toAjax(bizAgencyService.updateBizAgency(bizAgency));
    }

    /**
     * 删除【请填写功能名称】
     */
    @ApiOperation("删除")
    @PreAuthorize("@ss.hasPermi('system:agency:remove')")
    @Log(title = "删除代理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{agencyIds}")
    public AjaxResult remove(@PathVariable Long[] agencyIds)
    {
        return toAjax(bizAgencyService.deleteBizAgencyByAgencyIds(agencyIds));
    }
}
